﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="FlowDiagram.aspx.cs" Inherits="bts_webapp.FlowDiagram" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>


<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script language="javascript" type="text/javascript" src="Scripts/joint.all.min.js"></script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="clear:both;">
    <asp:ScriptManager ID="sMan" runat="server" />
    <table style="height:300px; width:99%; background-color:White;">
        <tr>
            <td style="width:40%; vertical-align:top;">
                <div style="border-bottom:1px solid;">Chọn  trạm để xem</div>
                <br />
                <telerik:RadTreeView ID="tree" runat="server" OnNodeClick="tree_NodeClick4" />
                <br />
                <div style="border-top:1px solid;">
                    <span style="background-color:#00CC00;">&nbsp;&nbsp;&nbsp;</span>: Trạm đi
                    <br />
                    <span style="background-color:Yellow;">&nbsp;&nbsp;&nbsp;</span>: Trạm chọn
                    <br />
                    <span style="background-color:Red;">&nbsp;&nbsp;&nbsp;</span>: Trạm đến
                    <br />
                    <asp:Button ID="btPrint" runat="server" OnClick="btPrint_Click" Text="In sơ đồ" />
                </div>
                
            </td>
            <td style="width: 800px; border-left: 2px solid; vertical-align:top;">
                <div id="diagram">
                </div>
            </td>
        </tr>
    </table>
    <asp:HiddenField ID="hfStation" runat="server" />
    <asp:HiddenField ID="hfDevices" runat="server" />
    <asp:HiddenField ID="hfCards" runat="server" />
    <asp:HiddenField ID="hfCardsIncoming" runat="server" />
    <asp:HiddenField ID="hfCardsOutcoming" runat="server" />
    <asp:HiddenField ID="hfCardsCenterIn" runat="server" />
    <asp:HiddenField ID="hfCardsCenterOut" runat="server" />
    <asp:HiddenField ID="hfIncomingStation" runat="server" />
    <asp:HiddenField ID="hfOutgoingStation" runat="server" />
    <asp:HiddenField ID="hflag" runat="server" />
    
    </div>

    <telerik:RadCodeBlock ID="rcb" runat="server">
        <script language="javascript" type="text/javascript">

            makeDiagram4(800, 16000);
            
        function makeDiagram(width, height) {

            var org = Joint.dia.org;
            Joint.paper("diagram", width, height);

            //========= for station ==============================
            var pXStation = 300;
            var pYStation = 5;
            var stationName = $get('<%= hfStation.ClientID %>').value;

            var station = org.Member.create({
                rect: { x: pXStation, y: pYStation, width: 160, height: 60 },
                name: stationName,
                avatar: 'Image/Station.png',
                attrs: { fill: 'yellow', stroke: 'brown' }
            });

            //============= devices =========================================
            /*var pXDevice = 460;*/
            var pXDevice = 400;
            var pYDevice = 100;
            var deviceVal = $get('<%= hfDevices.ClientID %>').value;
            if (deviceVal != "") {
                var deviceNames = $get('<%= hfDevices.ClientID %>').value.split('|');
                var deviceList = [];
                for (var i = 0; i < deviceNames.length; i++) {
                    var device = org.Member.create({
                        rect: { x: pXDevice, y: pYDevice, width: 30, height: 30 },
                        name: deviceNames[i],
                        avatar: 'Image/Device.png',
                        attrs: { fill: 'green', stroke: 'brown' }
                    });
                    deviceList.push(device);
                    pYDevice += 60;
                }
            }

            
            //============== incoming stations ===============================
            var pXIncoming = 5;
            var pYIncoming = 5;
            var incomingVal = $get('<%= hfIncomingStation.ClientID %>').value;
            var incomingList = [];
            if (incomingVal != "") {
                
                var incomingStationNames = incomingVal.split('|');

                for (var i = 0; i < incomingStationNames.length; i++) {
                    var currentVal = incomingStationNames[i];
                    var incomingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >=0 )
                        incomingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < incomingStationNames2.length; j++) {
                        if (incomingStationNames2[j].trim() == "")
                            continue;
                        var incomingStation = org.Member.create({
                            rect: { x: pXIncoming, y: pYIncoming, width: 140, height: 60 },
                            name: incomingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'blue', stroke: 'White' }
                        });
                        tempList.push(incomingStation);
                        pYIncoming += 90;
                    }
                    incomingList.push(tempList);
                }
            }

            //============== outgoing stations ========================
            /*var pXOutgoing = 780;*/
            var pXOutgoing = 600;
            var pYOutgoing = 5;
            var outgoingVal = $get('<%= hfOutgoingStation.ClientID %>').value;
            var outgoingList = [];
            if (outgoingVal != "") {
                var outgoingStationNames = outgoingVal.indexOf('@') >= 0 ? outgoingVal.split('|') : [outgoingVal];

                for (var i = 0; i < outgoingStationNames.length; i++) {
                    var currentVal = outgoingStationNames[i];
                    var outgoingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        outgoingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < outgoingStationNames2.length; j++) {
                        if (outgoingStationNames2[j].trim() == "")
                            continue;
                        var outgoingStation = org.Member.create({
                            rect: { x: pXOutgoing, y: pYOutgoing, width: 140, height: 60 },
                            name: outgoingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'red', stroke: 'brown' }
                        });

                        tempList.push(outgoingStation);
                        pYOutgoing += 80;
                    }
                    outgoingList.push(tempList);
                }
            }
                
            //================ link all together =========================
            
            var temp = station;
            for (var i = 0; i < deviceList.length; i++) {
                temp.joint(deviceList[i], org.arrow);
                temp = deviceList[i];
            }

            if (incomingList.length > 0) {
                for (var i = 0; i < deviceList.length; i++) {
                    var subIncomingList = incomingList[i];
                    for(var j=0; j<subIncomingList.length; j++)
                        deviceList[i].joint(subIncomingList[j], org.arrow);
                        
                }
            }

            if (outgoingList.length > 0){
                for (var i = 0; i < deviceList.length; i++) {
                    var subOutgoingList = outgoingList[i];
                    for(var j=0; j<subOutgoingList.length; j++)
                        deviceList[i].joint(subOutgoingList[j], org.arrow);
                }
            }

        }


        function makeDiagram2(width, height) {

            var org = Joint.dia.org;
            Joint.paper("diagram", width, height);

            //========= for station ==============================
            var pXStation = 300;
            var pYStation = 5;
            var stationName = $get('<%= hfStation.ClientID %>').value;

            var station = org.Member.create({
                rect: { x: pXStation, y: pYStation, width: 160, height: 60 },
                name: stationName,
                avatar: 'Image/Station.png',
                attrs: { fill: 'yellow', stroke: 'brown' }
            });

            //============= cards =========================================
            /*var pXDevice = 460;*/
            var pXCard = 400;
            var pYCard = 100;
            var cardVal = $get('<%= hfCards.ClientID %>').value;
            var cardList = [];
            if (cardVal != "") {
                var cardNames = $get('<%= hfCards.ClientID %>').value.split('|');
                
                for (var i = 0; i < cardNames.length; i++) {
                    var card = org.Member.create({
                        rect: { x: pXCard, y: pYCard, width: 30, height: 30 },
                        name: cardNames[i],
                        avatar: 'Image/Device.png',
                        attrs: { fill: 'green', stroke: 'brown' }
                    });
                    cardList.push(card);
                    pYCard += 60;
                }
            }


            //============== incoming stations ===============================
            var pXIncoming = 5;
            var pYIncoming = 5;
            var incomingVal = $get('<%= hfIncomingStation.ClientID %>').value;
            var incomingList = [];
            if (incomingVal != "") {

                var incomingStationNames = incomingVal.split('|');

                for (var i = 0; i < incomingStationNames.length; i++) {
                    var currentVal = incomingStationNames[i];
                    var incomingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        incomingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < incomingStationNames2.length; j++) {
                        if (incomingStationNames2[j].trim() == "")
                            continue;
                        var incomingStation = org.Member.create({
                            rect: { x: pXIncoming, y: pYIncoming, width: 140, height: 60 },
                            name: incomingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'blue', stroke: 'brown' }
                        });
                        tempList.push(incomingStation);
                        pYIncoming += 90;
                    }
                    incomingList.push(tempList);
                }
            }

            //============== outgoing stations ========================
            /*var pXOutgoing = 780;*/
            var pXOutgoing = 600;
            var pYOutgoing = 5;
            var outgoingVal = $get('<%= hfOutgoingStation.ClientID %>').value;
            var outgoingList = [];
            if (outgoingVal != "") {
                var outgoingStationNames = outgoingVal.indexOf('@') >= 0 ? outgoingVal.split('|') : [outgoingVal];

                for (var i = 0; i < outgoingStationNames.length; i++) {
                    var currentVal = outgoingStationNames[i];
                    var outgoingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        outgoingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < outgoingStationNames2.length; j++) {
                        if (outgoingStationNames2[j].trim() == "")
                            continue;
                        var outgoingStation = org.Member.create({
                            rect: { x: pXOutgoing, y: pYOutgoing, width: 140, height: 60 },
                            name: outgoingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'red', stroke: 'brown' }
                        });

                        tempList.push(outgoingStation);
                        pYOutgoing += 80;
                    }
                    outgoingList.push(tempList);
                }
            }

            //================ link all together =========================
            
            var temp = station;
            for (var i = 0; i < cardList.length; i++) {
                temp.joint(cardList[i], org.arrow);
                temp = cardList[i];
                
            }

            if (incomingList.length > 0) {
                for (var i = 0; i < cardList.length; i++) 
                {
                    var subIncomingList = incomingList[i];
                    for (var j = 0; j < subIncomingList.length; j++)
                        cardList[i].joint(subIncomingList[j], org.arrow);

                }
            }

            if (outgoingList.length > 0) {
                for (var i = 0; i < cardList.length; i++) 
                {
                    var subOutgoingList = outgoingList[i];
                    for (var j = 0; j < subOutgoingList.length; j++)
                        cardList[i].joint(subOutgoingList[j], org.arrow);
                }
            }

        }

        //Nha create 27/7/2012. ======================================================================================================

        function makeDiagram3(width, height) {

            var org = Joint.dia.org;
            Joint.paper("diagram", width, height);
            var flag = $get('<%=hflag.ClientID %>').value;

            //========= for station ==============================
            var pXStation = 300;
            var pYStation = 5;
            var stationName = $get('<%= hfStation.ClientID %>').value;

            var station = org.Member.create({
                rect: { x: pXStation, y: pYStation, width: 160, height: 60 },
                name: stationName,
                avatar: 'Image/Station.png',
                attrs: { fill: 'yellow', stroke: 'brown' }
            });
            
            //============= cards goc =========================================
            /*var pXDevice = 460;*/
            var pXCard = 370;
            var pYCard = 100;
            if (flag == '0') {//khong phai la tram goc
                pXCard = 60;
                pYCard = 100;
            }
            var cardVal = $get('<%= hfCardsIncoming.ClientID %>').value;
            var cardList = [];
            if (cardVal != "") {
                var cardNames = $get('<%= hfCardsIncoming.ClientID %>').value.split('|');
                for (var i = 0; i < cardNames.length; i++) {
                    var card = org.Member.create({
                        rect: { x: pXCard, y: pYCard, width: 30, height: 30 },
                        name: cardNames[i],
                        avatar: 'Image/Device.png',
                        attrs: { fill: 'green', stroke: 'brown' }
                    });
                    cardList.push(card);
                    pYCard += 60;
                }
            }

            //===============card ngon ======================================
            var pXCardOut = 520;
            var pYCardOut = 30;
            if (flag == '0') {

                pXCardOut = 370;
                pYCardOut = 100;
            }
            var cardOutVal = $get('<%= hfCardsOutcoming.ClientID %>').value;
            var cardListOut = [];
            if (cardOutVal != "") {
                            
                var OutcardNames = cardOutVal.indexOf('@') >= 0 ? cardOutVal.split('|') : [cardOutVal];

                for (var i = 0; i < OutcardNames.length; i++) {
                    var currentVal = OutcardNames[i];
                    var OutcardNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        OutcardNames2 = currentVal.split('@');
                    var tempListOut = [];
                    for (var j = 0; j < OutcardNames2.length; j++) {
                        if (OutcardNames2[j].trim() == "")
                            continue;
                        var outcomingCard = org.Member.create({
                            rect: { x: pXCardOut, y: pYCardOut, width: 30, height: 30 },
                            name: OutcardNames2[j],
                            avatar: 'Image/Device.png',
                            attrs: { fill: 'green', stroke: 'brown' }
                        });
                        tempListOut.push(outcomingCard);
                        pYCardOut += 80;
                    }
                    cardListOut.push(tempListOut);
                            
                }
            }


            //============== incoming stations ===============================
            var pXIncoming = 5;
            var pYIncoming = 5;
            var incomingVal = $get('<%= hfIncomingStation.ClientID %>').value;
            var incomingList = [];
            if (incomingVal != "") {

                var incomingStationNames = incomingVal.split('|');

                for (var i = 0; i < incomingStationNames.length; i++) {
                    var currentVal = incomingStationNames[i];
                    var incomingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        incomingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < incomingStationNames2.length; j++) {
                        if (incomingStationNames2[j].trim() == "")
                            continue;
                        var incomingStation = org.Member.create({
                            rect: { x: pXIncoming, y: pYIncoming, width: 140, height: 60 },
                            name: incomingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: '#00CC00', stroke: 'brown'}
                        });
                        tempList.push(incomingStation);
                        pYIncoming += 90;
                    }
                    incomingList.push(tempList);
                }
            }

            //============== outgoing stations ========================
            /*var pXOutgoing = 780;*/
            var pXOutgoing = 600;
            var pYOutgoing = 5;
            var outgoingVal = $get('<%= hfOutgoingStation.ClientID %>').value;
            var outgoingList = [];
            if (outgoingVal != "") {
                var outgoingStationNames = outgoingVal.indexOf('@') >= 0 ? outgoingVal.split('|') : [outgoingVal];

                for (var i = 0; i < outgoingStationNames.length; i++) {
                    var currentVal = outgoingStationNames[i];
                    var outgoingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        outgoingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < outgoingStationNames2.length; j++) {
                        if (outgoingStationNames2[j].trim() == "")
                            continue;
                        var outgoingStation = org.Member.create({
                            rect: { x: pXOutgoing, y: pYOutgoing, width: 140, height: 60 },
                            name: outgoingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'red', stroke: 'brown' }
                        });

                        tempList.push(outgoingStation);
                        pYOutgoing += 80;
                    }
                    outgoingList.push(tempList);
                }
            }

            //================ link all together =========================
           
            var temp = station;

            if (flag == '0') {
                if (cardListOut.length > 0) {
                    for (var i = 0; i < cardList.length; i++) {
                        var subOutgoingCardList = cardListOut[i];
                        var subOutgoingStationList = outgoingList[i];
                        for (var j = 0; j < subOutgoingCardList.length; j++) {
                            cardList[i].joint(subOutgoingCardList[j], org.arrow);

                        }
                    }
                }

//                if (incomingList.length > 0) {
//                    for (var i = 0; i < cardList.length; i++) {
//                        var subIncomingList = incomingList[i];
//                        for (var j = 0; j < subIncomingList.length; j++)
//                            cardList[i].joint(subIncomingList[j], org.arrow);

//                    }
//                    
//                }

                

            }
            else {
                
                for (var i = 0; i < cardList.length; i++) {
                    temp.joint(cardList[i], org.arrow);
                    temp = cardList[i];

                }

                if (incomingList.length > 0) {
                    for (var i = 0; i < cardList.length; i++) {
                        var subIncomingList = incomingList[i];
                        for (var j = 0; j < subIncomingList.length; j++)
                            cardList[i].joint(subIncomingList[j], org.arrow);

                    }
                }

                if (cardListOut.length > 0) {
                    for (var i = 0; i < cardList.length; i++) {
                        var subOutgoingCardList = cardListOut[i];
                        var subOutgoingStationList = outgoingList[i];
                        for (var j = 0; j < subOutgoingCardList.length; j++) {
                            cardList[i].joint(subOutgoingCardList[j], org.arrow);

                        }

                        for (var k = 0; k < subOutgoingCardList.length; k++) {
                            subOutgoingCardList[k].joint(subOutgoingStationList[k], org.arrow);
                        }
                    }
                }
            }
        }

        //========================================================================================================================
        function makeDiagram4(width, height) {

            var org = Joint.dia.org;
            Joint.paper("diagram", width, height);
            var flag = $get('<%=hflag.ClientID %>').value;

            //========= for station ==============================
            var pXStation = 300;
            var pYStation = 5;
            var stationName = $get('<%= hfStation.ClientID %>').value;

            var station = org.Member.create({
                rect: { x: pXStation, y: pYStation, width: 160, height: 60 },
                name: stationName,
                avatar: 'Image/Station.png',
                attrs: { fill: 'yellow', stroke: 'brown' }
            });
            var Card = [];
            if (flag == '2') {
                var pXInCenterCard = 370;
                var pYInCenterCard = 100;
                var CenterCard = $get('<%= hfCards.ClientID %>').value;
                if (CenterCard != null) {
                    var CenterCardName = $get('<%= hfCards.ClientID %>').value.split('@');
                    var tempListCardCenter = [];
                    for (var i = 0; i < CenterCardName.length-1; i++) {
                        var InCard = org.Member.create({
                            rect: { x: pXInCenterCard, y: pYInCenterCard, width: 30, height: 30 },
                            name: CenterCardName[i],
                            avatar: 'Image/Device.png',
                            attrs: { fill: 'green', stroke: 'brown' }
                        });
                        tempListCardCenter.push(InCard)
                        pYInCenterCard += 60;
                    }
                    Card.push(tempListCardCenter);                    
                }
            }
            //============= cards goc =========================================
            /*var pXDevice = 460;*/
            var pXCard = 370;
            var pYCard = 100;
            if (flag == '0') {//khong phai la tram goc
                pXCard = 60;
                pYCard = 100;
            }
            if (flag == '2') {
                pXCard = 30;
                pYCard = 100;
            }
            var cardVal = $get('<%= hfCardsIncoming.ClientID %>').value;
            var cardList = [];
            if (cardVal != "") {
                var cardNames = $get('<%= hfCardsIncoming.ClientID %>').value.split('@');
                for (var i = 0; i < cardNames.length-1; i++) {
                    var cardin = org.Member.create({
                        rect: { x: pXCard, y: pYCard, width: 30, height: 30 },
                        name: cardNames[i],
                        avatar: 'Image/Device.png',
                        attrs: { fill: 'green', stroke: 'brown' }
                    });
                    cardList.push(cardin);
                    pYCard += 60;
                }
            }
            //===============card ngon ======================================
            var pXCardOut = 520;
            var pYCardOut = 30;
            if (flag == '0' && flag != '2') {

                pXCardOut = 370;
                pYCardOut = 100;
            }
            var cardOutVal = $get('<%= hfCardsOutcoming.ClientID %>').value;
            var cardListOut = [];
            if (cardOutVal != "") {

                var OutcardNames = cardOutVal.indexOf('@') >= 0 ? cardOutVal.split('|') : [cardOutVal];

                for (var i = 0; i < OutcardNames.length; i++) {
                    var currentVal = OutcardNames[i];
                    var OutcardNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        OutcardNames2 = currentVal.split('@');
                    var tempListOut = [];
                    for (var j = 0; j < OutcardNames2.length; j++) {
                        if (OutcardNames2[j].trim() == "")
                            continue;
                        var outcomingCard = org.Member.create({
                            rect: { x: pXCardOut, y: pYCardOut, width: 30, height: 30 },
                            name: OutcardNames2[j],
                            avatar: 'Image/Device.png',
                            attrs: { fill: 'green', stroke: 'brown' }
                        });
                        tempListOut.push(outcomingCard);
                        pYCardOut += 80;
                    }
                    cardListOut.push(tempListOut);
                }
            }
            //============== incoming stations ===============================
            var pXIncoming = 5;
            var pYIncoming = 5;
            var incomingVal = $get('<%= hfIncomingStation.ClientID %>').value;
            var incomingList = [];
            if (incomingVal != "") {

                var incomingStationNames = incomingVal.split('@');

                for (var i = 0; i < incomingStationNames.length; i++) {
                    var currentVal = incomingStationNames[i];
                    var incomingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        incomingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < incomingStationNames2.length; j++) {
                        if (incomingStationNames2[j].trim() == "")
                            continue;
                        var incomingStation = org.Member.create({
                            rect: { x: pXIncoming, y: pYIncoming, width: 140, height: 60 },
                            name: incomingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: '#00CC00', stroke: 'brown' }
                        });
                        tempList.push(incomingStation);
                        pYIncoming += 40;
                    }
                    incomingList.push(tempList);
                }
            }

            //============== outgoing stations ========================
            /*var pXOutgoing = 780;*/
            var pXOutgoing = 600;
            var pYOutgoing = 5;
            var outgoingVal = $get('<%= hfOutgoingStation.ClientID %>').value;
            var outgoingList = [];
            if (outgoingVal != "") {
                var outgoingStationNames = outgoingVal.indexOf('@') >= 0 ? outgoingVal.split('|') : [outgoingVal];

                for (var i = 0; i < outgoingStationNames.length; i++) {
                    var currentVal = outgoingStationNames[i];
                    var outgoingStationNames2 = [currentVal];
                    if (currentVal.indexOf('@') >= 0)
                        outgoingStationNames2 = currentVal.split('@');
                    var tempList = [];
                    for (var j = 0; j < outgoingStationNames2.length; j++) {
                        if (outgoingStationNames2[j].trim() == "")
                            continue;
                        var outgoingStation = org.Member.create({
                            rect: { x: pXOutgoing, y: pYOutgoing, width: 140, height: 60 },
                            name: outgoingStationNames2[j],
                            avatar: 'Image/Station.png',
                            attrs: { fill: 'red', stroke: 'brown' }
                        });

                        tempList.push(outgoingStation);
                        pYOutgoing += 80;
                    }
                    outgoingList.push(tempList);
                }
            }
            //================ link all together =========================
            var temp = station;
            if (flag == '0') {
                if (cardListOut.length > 0) {
                    for (var i = 0; i < cardList.length; i++) {
                        var subOutgoingCardList = cardListOut[i];
                        var subOutgoingStationList = outgoingList[i];
                        for (var j = 0; j < subOutgoingCardList.length; j++) {
                            cardList[i].joint(subOutgoingCardList[j], org.arrow);
                        }
                    }
                }
            }
            else {
                if (flag == '1') {
                    for (var i = 0; i < cardList.length; i++) {
                        temp.joint(cardList[i], org.arrow);
                        temp = cardList[i];
                    }
                    if (incomingList.length > 0) {
                        for (var i = 0; i < cardList.length; i++) {
                            var subIncomingList = incomingList[i];
                            for (var j = 0; j < subIncomingList.length; j++)
                                cardList[i].joint(subIncomingList[j], org.arrow);
                        }
                    }
                    if (cardListOut.length > 0) {
                        for (var i = 0; i < cardList.length; i++) {
                            var subOutgoingCardList = cardListOut[i];                            
                            for (var j = 0; j < subOutgoingCardList.length; j++) {
                                cardList[i].joint(subOutgoingCardList[j], org.arrow);
                            }

                            var subOutgoingStationList = outgoingList[i];
                            for (var k = 0; k < subOutgoingCardList.length; k++) {
                                subOutgoingCardList[k].joint(subOutgoingStationList[k], org.arrow);
                            }
                        }
                    }
                }
                else {// flag=2
                    // Card - card trung tam
                    // cardList - card goc
                    // cardListOut - card ngon
                    // temp - tram trung tam
                    // incomingList - tram goc
                    // outgoingList - tram ngon
                    if (Card.length > 0) {
                        for (var i = 0; i < cardList.length; i++) {
                            var subIncomingList = Card[i];
                            for (var j = 0; j < subIncomingList.length - 1; j++) {
                                cardList[i].joint(subIncomingList[j], org.arrow);
                            }
                        }                        
                    }
                    if (cardListOut.length > 0) {
                        for (var i = 0; i < Card.length; i++) {                            
                            var subOutgoingCardList = cardListOut[i];                           
                            var subOutgoingStationList = outgoingList[i];
                            for (var k = 0; k < subOutgoingCardList.length; k++) {
                                subOutgoingCardList[k].joint(subOutgoingStationList[k], org.arrow);
                                Card[i].joint(subOutgoingCardList[k], org.arrow);
                            }
                           
                        }
                    }

//                    if (cardListOut.length > 0) {
//                        for (var k = 0; k < Card.length; k++) {
//                            var subOutgoingCardList = cardListOut[k];
//                            for (var j = 0; j < subOutgoingCardList.length ; j++) {
//                                Card[k].joint(subOutgoingCardList[j], org.arrow);
//                            }
//                        }
//                    }
                   
                }                
            }
        }


        </script>
    </telerik:RadCodeBlock>

</asp:Content>
